package org.hq.mapper;
import org.hq.pojo.WebUser;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.DigestUtils;

import java.nio.charset.Charset;

@SpringBootTest
class UserMapperTest {
    @Autowired
    UserMapper<WebUser> user;
    //密码
    @Autowired
    private PasswordEncoder pw;
    @Test
    void insert() {
        user.insert(new WebUser());
    }

    @Test
    void testInsert() {
        //密码加密.getBytes(Charset.forName("UTF-8"))
        String password =  pw.encode("123456");
        //用户添加
        int u =user.insert(new WebUser("qiao", "何桥", password, "admin"));
        System.out.println(u);
        u =user.insert(new WebUser("he", "何桥", password, "admin"));
        System.out.println(u);
    }


    @Test
    void selectUserId() {
        WebUser user = new WebUser();
        user.setUserid("qq");
        WebUser root = this.user.selectUserId(user);
        System.out.println( root.getUserid());

        /*
        BCryptPasswordEncoder pe = new BCryptPasswordEncoder();
        String password = pe.encode("12345");
        String passwordS = pe.encode("12345");
        //$2a$10$XS3XmhSM3gD5.LMxFSZVmOTrtRA9tbg9y1b2bHIQQ17n7IZ5mqu/q

        System.out.println(password);
        System.out.println(passwordS);
        System.out.println(password.equals("$2a$10$5570jJ5i6ed0HdT.IfwA9upwyJdWBUijDA.nw.ML/8wTYSPEpemvW"));
*/

    }

    @Test
    void jiami(){

        //md5加密
        String md5Pswd1 = DigestUtils.md5DigestAsHex("123456".getBytes());
        String md5Pswd2 = DigestUtils.md5DigestAsHex("123456".getBytes());
        System.out.println(md5Pswd1);
        System.out.println(md5Pswd2);
        System.out.println(md5Pswd1.equals(md5Pswd2));

        System.out.println("-------------------------------------");

        String password1 = BCrypt.hashpw("123456", BCrypt.gensalt());
        String password2 = BCrypt.hashpw("123456", BCrypt.gensalt());
        System.out.println(password1);
        System.out.println(password2);
        System.out.println(password1.equals(password2));
    }



}